package com.xoms.admin.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.admin.controller.res.*;
import com.xoms.admin.controller.res.bean.*;
import com.xoms.admin.controller.springmvc.req.*;

/**
 * 商品库存盘库相关接口
 **/
@Controller
@RequestMapping(value = "/check", produces = "application/json")
public class SProCheckController {
	@Autowired
	com.xoms.admin.controller.ProCheckController proCheckController;

	/**
	 * 盘库-获取列表
	 **/
	@RequestMapping("/v1/getChecks")
	@ResponseBody
	public ListResult<RProCheckBean> getChecks(@Validated GetProChecksParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProCheckBean> res = new ListResult<RProCheckBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proCheckController.getChecks(param, request, response);
	}

	/**
	 * 盘库-获取详情
	 **/
	@RequestMapping("/v1/getCheckDetails")
	@ResponseBody
	public ListResult<RProCheckProInfoBean> getCheckDetails(@Validated GetCheckDetailsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProCheckProInfoBean> res = new ListResult<RProCheckProInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proCheckController.getCheckDetails(param, request, response);
	}

	/**
	 * 盘库-新建、编辑
	 **/
	@RequestMapping("/v1/editCheck")
	@ResponseBody
	public ObjectResult<RProCheckBean> editCheck(@Validated EditCheckParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProCheckBean> res = new ObjectResult<RProCheckBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proCheckController.editCheck(param, request, response);
	}

	/**
	 * 盘库-删除信息
	 **/
	@RequestMapping("/v1/delCheck")
	@ResponseBody
	public BaseResult delCheck(@Validated DelCheckParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proCheckController.delCheck(param, request, response);
	}

	/**
	 * 盘库-提交审核
	 **/
	@RequestMapping("/v1/submitCheck")
	@ResponseBody
	public BaseResult submitCheck(@Validated SubCheckParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proCheckController.submitCheck(param, request, response);
	}
}
